﻿@section header {
    <script type="text/javascript">
        /**
        * chw 2011.4.7
        * panel: 主面板
        */
        Ext.onReady(function () {
            var panel = Ext.create('Ext.panel.Panel', {
                region: 'center',
                layout: {
                    type: 'hbox',
                    align: 'stretch'
                    //pack: 'start'
                },
                defaults: {
                    flex: 1 //子元素平均分配宽度
                },
                split: true,
                autoScroll: true,
                bodyPadding: 0,
                border: 0,
                padding: 0,
                margin: 0,
                tbar: [
                          { xtype: 'label', text: '权限管理 -> 分级权限', cls: 'formNav' },
                          { xtype: 'tbfill' },
                          { xtype: 'button', iconCls: 'helpIcon', tooltip: '帮助', tooltipType: 'title', handle: function (source, e) { alert('帮助!') } }
                          ]/*,
                bbar: [
                          { xtype: 'button', text: 'Button 1', handler: function (source, e) { openWindow(); } }
                        ],
                html: ''*/
            });
            new Ext.container.Viewport({
                layout: 'border',
                border: 0,
                items: [
                panel
                ]
            });

            Ext.regModel('user', {
                //            fields: ['ID','privilegeName', 'resourceCode', 'privilegeCode']
                fields: [
            { name: 'ID', type: 'int' },
            { name: 'Code', type: 'string' },
            { name: 'Name', type: 'string' },
            { name: 'Password', type: 'string' },
            { name: 'MOBILE', type: 'string' },
            { name: 'Org', type: 'string' },
            { name: 'Summary', type: 'string' }
            ]
            });

            var roleGrid = new Ext.grid.GridPanel({
                title: '用户列表',
                store: new Ext.data.ArrayStore({
                    model: 'user',
                    sorters: ['ID'],
                    data: [
                    ['1', 'admin', '超级管理员', 'abc', '13701220222', '信息中心', '超级管理员是系统管理员,拥有最高管理级别'],
                    ['2', 'lilin', '李林', 'abc', '13701220222', '信息中心', ''],
                    ['3', 'lxf', 'lxf', 'abc', '13701220222', '设计科', ''],
                    ['4', 'lxx', 'lxx', 'abc', '13701220222', '办公室', '普通用户'],
                    ['5', 'wh', 'wh', 'abc', '13701220222', '设计科', '普通用户'],
                    ['6', 'zm', 'zm', 'abc', '13701220222', '设计科', '普通用户'],
                    ['7', 'wzheng', 'wzheng', 'abc', '13701220222', '设计科', '普通用户'],
                    ['8', 'xq', 'xq', 'abc', '13701220222', '设计科', '普通用户'],
                    ['9', 'ljm', 'ljm', 'abc', '13701220222', '设计科', '普通用户'],
                    ['10', 'df', 'df', 'abc', '13701220222', '设计科', '普通用户']
                ]
                }),
                margin: 6,
                autoScroll: true,
                border: 0,
                padding: 0,
                bodyPadding: 0,
                flex: 4,
                stripeRows: true,
                plugins: [new Ext.grid.CellEditing({ clicksToEdit: 2 })],
                selModel: { selType: 'cellmodel' },
                tbar: [
                          { xtype: 'button', iconCls: 'iconNew', text: '', tooltip: '新建用户', tooltipType: 'title', handler: function (source, e) { NewUser(); } },
                          { xtype: 'button', iconCls: 'iconEdit', text: '', tooltip: '编辑用户', tooltipType: 'title', handler: function (source, e) { Ext.getCmp('grid001').view.refresh(); } },
                          { xtype: 'button', iconCls: 'iconDelete', text: '', tooltip: '删除用户', tooltipType: 'title', handler: function (source, e) { Ext.getCmp('grid001').view.refresh(); } },
                          { xtype: 'tbseparator' },
                          { xtype: 'tbfill' },
                          { xtype: 'button', iconCls: 'iconRefresh', text: '', tooltip: '刷新', tooltipType: 'title', handler: function (source, e) { alert('刷新!') } }
                        ],
                frame: true,
                columns: [
                new Ext.grid.RowNumberer(),
                {
                    text: 'ID',
                    dataIndex: 'ID',
                    width: 100,
                    hidden: true
                }, {
                    text: '用户编码',
                    dataIndex: 'Code',
                    width: 100,
                    field: { allowBlank: false }
                }, {
                    text: '用户名称',
                    dataIndex: 'Name',
                    width: 160,
                    field: { allowBlank: false },
                    renderer: function (v) { return '<a href="#">' + v + '</a>'; }
                }, {
                    text: '手机',
                    dataIndex: 'MOBILE',
                    width: 100,
                    field: { allowBlank: false }
                }, {
                    text: '用户口令',
                    dataIndex: 'Password',
                    width: 100,
                    field: { allowBlank: false }
                }, {
                    text: '所在部门',
                    dataIndex: 'Org',
                    //renderer: function (v) { return '<a href="#">' + v + '</a>'; },
                    width: 160,
                    field: {
                        xtype: 'combobox',
                        typeAhead: true,
                        triggerAction: 'all',
                        store: [
                            ['办公室', '办公室'],
                            ['信息中心', '信息中心'],
                            ['设计科', '设计科'],
                            ['财务科', '财务科'],
                            ['其他', '其他']
                        ],
                        lazyRender: true,
                        listClass: 'x-combo-list-small'
                    }
                }, {
                    text: '说明',
                    dataIndex: 'Summary',
                    //renderer: function (v) { return '<a href="#">' + v + '</a>'; },
                    flex: 1
                    //field: { allowBlank: false },
                }, {
                    text: '操作',
                    //dataIndex: 'Summary',
                    width: 50,
                    align: 'center',
                    renderer: function (v) { return '<span class="iconEdit" style="width:20px;height:18px;" title="修改"></span><span class="iconDelete" style="width:20px;height:18px;" title="删除"></span>'; }
                }],
                viewConfig: {
                    listeners: {
                        //                    itemdblclick: function (view, record, el, index, e) { /*alert(record.get("ID"))*/winMR.show(this) },
                        itemclick: function (view, record, el, index, e) {
                            //debugger;
                            uGrid.setTitle(record.data.Name + ' - 分级管理用户');
                            privilegeGrid.setTitle(record.data.Name + ' - 分级管理权限');
                            //debugger;
                            //roleGrid.store.getAt(0).set('privilegeName', 'ddddddddddddd');
                            //debugger;
                            //roleGrid.store.getAt(0).dirty = true;
                            //roleGrid.getView().refreshNode(0);
                            roleGrid.getView().refresh();
                            //                        debugger;
                            //                        roleGrid.store.load();
                        }
                    }
                }
            }); // grid

            var cont = new Ext.container.Container({
                layout: {
                    type: 'vbox',
                    align: 'stretch'
                },
                margin: 6,
                flex: 1
            });

            var uGrid = new Ext.grid.GridPanel({
                title: roleGrid.store.getAt(0).data.Name + ' - 分级管理用户',
                store: new Ext.data.ArrayStore({
                    fields: [{ name: 'code', type: 'string' }, { name: 'name', type: 'string'}],
                    data: [['lilin', '李林'], ['zj', '张竞']]
                }),
                flex: 1,
                align: 'stretch',
                frame: true,
                //width: '100%',
                plugins: [new Ext.grid.CellEditing({ clicksToEdit: 2 })],
                selModel: { selType: 'cellmodel' },
                tbar: [
                          { xtype: 'button', iconCls: 'iconNew', text: '', tooltip: '增加用户', tooltipType: 'title', handler: function (source, e) { alert('增加用户') } },
                          { xtype: 'tbseparator' },
                          { xtype: 'tbfill' },
                          { xtype: 'button', iconCls: 'iconRefresh', text: '', tooltip: '刷新', tooltipType: 'title', handler: function (source, e) { alert('刷新!') } }
                        ],
                columns: [
                new Ext.grid.RowNumberer(),
                {
                    header: '角色编码',
                    flex: 1,
                    dataIndex: 'code'
                }, {
                    header: '角色名称',
                    flex: 1,
                    dataIndex: 'name'
                }, {
                    text: '删除',
                    //dataIndex: 'Summary',
                    width: 40,
                    align: 'center',
                    renderer: function (v) { return '<span class="iconDelete" style="width:20px;height:18px;" title="删除" onclick="alert(\'取消当前指派!\')"></span>'; }
                }],
                viewConfig: {
                //                    listeners: {
                //                        itemdblclick: function (view, record, el, index, e) { /*alert(record.get("ID"))*/winMR.show(this) }
                //                    }
            }
        }); // grid

        var privilegeGrid = new Ext.grid.GridPanel({
            title: roleGrid.store.getAt(0).data.Name + ' - 分级管理权限',
            store: new Ext.data.ArrayStore({
                fields: [{ name: 'code', type: 'string' }, { name: 'name', type: 'string'}],
                data: [['devMaster', '设备主记录'], ['devManage', '设备管理']]
            }),
            margin: '6 0 0 0',
            flex: 1,
            frame: true,
            width: '100%',
            plugins: [new Ext.grid.CellEditing({ clicksToEdit: 2 })],
            selModel: { selType: 'cellmodel' },
            tbar: [
                          { xtype: 'button', iconCls: 'iconNew', text: '', tooltip: '增加权限', tooltipType: 'title', handler: function (source, e) { alert('增加权限') } },
                          { xtype: 'tbseparator' },
                          { xtype: 'tbfill' },
                          { xtype: 'button', iconCls: 'iconRefresh', text: '', tooltip: '刷新', tooltipType: 'title', handler: function (source, e) { alert('刷新!') } }
                        ],
            columns: [
                new Ext.grid.RowNumberer(),
                {
                    header: '角色编码',
                    flex: 1,
                    dataIndex: 'code'
                }, {
                    header: '角色名称',
                    flex: 1,
                    dataIndex: 'name'
                }, {
                    text: '删除',
                    //dataIndex: 'Summary',
                    width: 40,
                    align: 'center',
                    renderer: function (v) { return '<span class="iconDelete" style="width:20px;height:18px;" title="删除" onclick="alert(\'取消当前指派!\')"></span>'; }
                }],
            viewConfig: {
            //                    listeners: {
            //                        itemdblclick: function (view, record, el, index, e) { /*alert(record.get("ID"))*/winMR.show(this) }
            //                    }
        }
    }); // grid

    panel.add(roleGrid);
    panel.add(cont);
    cont.add(uGrid);
    cont.add(privilegeGrid);



    var userNewWindow = Ext.create('widget.window', {
        title: '权限管理->新建用户',
        modal: true,
        closable: true,
        closeAction: 'hide',
        //animateTarget: this,
        width: 800,
        height: 500,
        layout: 'fit',
        bodyStyle: 'padding: 5px;',
        items: [
            new Ext.form.FormPanel({
                autoHeight: true,
                autoScroll: true,
                bodyStyle: 'padding:5px 5px 0',
                fieldDefaults: {
                    labelAlign: 'top',
                    msgTarget: 'side',
                    width: '100%',
                    margin: "4 10",
                    anchor: '100%',
                    columnWidth: .5
                },
                layout: 'column',
                //                defaults: {
                //                    border: false,
                //                    layout: {
                //                        type: 'column', 
                //                        defaults: { width: '100%', }
                //                        }
                //                },
                items: [
                    {
                        xtype: 'textfield',
                        name: '用户编码',
                        fieldLabel: '用户编码',
                        allowBlank: false
                    }, {
                        xtype: 'textfield',
                        name: '用户名称',
                        fieldLabel: '用户名称',
                        allowBlank: false
                    }, {
                        xtype: 'textfield',
                        name: '初始口令',
                        fieldLabel: '初始口令',
                        allowBlank: false
                    }, {
                        xtype: 'textfield',
                        name: '确认初始口令',
                        fieldLabel: '确认初始口令',
                        allowBlank: false
                    }, {
                        xtype: 'datefield',
                        name: '创建时间',
                        fieldLabel: '创建时间',
                        columnWidth: .34,
                        allowBlank: false
                    }, {
                        xtype: 'datefield',
                        name: '生效时间',
                        fieldLabel: '生效时间',
                        columnWidth: .33,
                        allowBlank: false
                    }, {
                        xtype: 'datefield',
                        name: '到期时间',
                        fieldLabel: '到期时间',
                        columnWidth: .33,
                        allowBlank: false
                    }, {
                        xtype: 'fieldset',
                        title: '联系方式',
                        collapsible: true,
                        columnWidth: 1,
                        layout: 'column',
                        margin: 10,
                        items: [{
                            xtype: 'textfield',
                            name: '手机',
                            fieldLabel: '手机',
                            columnWidth: .34,
                            allowBlank: false
                        }, {
                            xtype: 'textfield',
                            name: '办公电话一',
                            columnWidth: .33,
                            fieldLabel: '办公电话一',
                            allowBlank: false
                        }, {
                            xtype: 'textfield',
                            name: '办公电话二',
                            columnWidth: .33,
                            fieldLabel: '办公电话二',
                            allowBlank: false
                        }, {
                            xtype: 'textfield',
                            name: '电子邮箱',
                            fieldLabel: '电子邮箱',
                            columnWidth: .34,
                            allowBlank: false
                        }, {
                            xtype: 'textfield',
                            name: 'QQ',
                            columnWidth: .33,
                            fieldLabel: 'QQ',
                            allowBlank: false
                        }, {
                            xtype: 'textfield',
                            name: 'MSN',
                            columnWidth: .33,
                            fieldLabel: 'MSN',
                            allowBlank: false
                        }]
                    }, {
                        xtype: 'htmleditor',
                        name: '备注',
                        columnWidth: 1,
                        fieldLabel: '备注',
                        allowBlank: false
                    }
                ],
                buttons: [{
                    text: '保存',
                    handler: function () { alert('保存') }
                }, {
                    text: '取消',
                    handler: function () { alert('取消') }
                }]
            })
            ]
    });

    NewUser = function () {
        userNewWindow.show();
    }

});                              // Ext.onReady

            
    </script>
}
